package floatingactionbutton.zjitc.net.androidhomeworktab;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

/**
 * @author 朱志文
 * @data 2019/9/28 0028
 */
public class MyPagerAdapter extends PagerAdapter {
    List<String> titiles;
    List<View> list;

    public MyPagerAdapter(List<String> titiles, List<View> list) {
        this.titiles = titiles;
        this.list = list;
    }

    @NonNull
    @Override
    public Object instantiateItem(@NonNull ViewGroup container, int position) {
        container.addView(list.get(position));
        return list.get(position);
    }

    @Override
    public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
        container.removeView(list.get(position));
    }


    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {
        return titiles.get(position);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public boolean isViewFromObject(@NonNull View view, @NonNull Object o) {
        return view==o;
    }
}
